/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on Apr 24, 2009, 10:08:07 AM
 */

package slideskinbuilder;

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.Color;
import java.io.File;
/**
 *
 * @author justin.hawkins
 */
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow */
    final JColorChooser colorChooser;
    final JDialog colorDialog;
    String filename;
    JFileChooser fc;

    public MainWindow() {
        initComponents();
        this.setTitle("SlideSkinBuilder 1.0 By Beardface");
        myinit();

        colorChooser  = new JColorChooser();
        filename = File.separator+"tmp";
        fc = new JFileChooser(new File(filename));

        this.topRadio.setSelected(true);

        // For okay button selection, change button background to
        // selected color
        ActionListener okActionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
                imagePanel.SetBackgroundColor(colorChooser.getColor());
                backgroundColorLabel.setText(colorChooser.getColor().toString());
            }
        };

        // For cancel button selection, change button background to red
        ActionListener cancelActionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
          }
        };

        colorDialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser,okActionListener, cancelActionListener);
    }

    public void myinit()
    {
        this.maxZoomSpin.setValue(100);
        this.minZoomSpin.setValue(50);
        this.falloffSpin.setValue(10);
        this.xSpin.setValue(200);
        this.ySpin.setValue(200);

        this.coverCountSpin.setValue(10);
        this.selectedSlider.setValue(50);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagePanel = new Viewer();
        backgroundColorButton = new javax.swing.JButton();
        backgroundColorLabel = new javax.swing.JLabel();
        backgroundImageButton = new javax.swing.JButton();
        backgroundImageLabel = new javax.swing.JLabel();
        foregroundImageButton = new javax.swing.JButton();
        foregroundImageLabel = new javax.swing.JLabel();
        coverGlowButton = new javax.swing.JButton();
        coverGlowLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        xSpin = new javax.swing.JSpinner();
        ySpin = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        centerRadio = new javax.swing.JRadioButton();
        topRadio = new javax.swing.JRadioButton();
        bottomRadio = new javax.swing.JRadioButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        glowSpinX = new javax.swing.JSpinner();
        glowSpinY = new javax.swing.JSpinner();
        jPanel1 = new javax.swing.JPanel();
        minZoomSpin = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        falloffSpin = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        maxZoomSpin = new javax.swing.JSpinner();
        functionCmb = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        spacingSlider = new javax.swing.JSpinner();
        jPanel3 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        coverCountSpin = new javax.swing.JSpinner();
        jLabel11 = new javax.swing.JLabel();
        selectedSlider = new javax.swing.JSlider();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        saveMenuItem = new javax.swing.JMenuItem();
        loadMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        imagePanel.setBackground(new java.awt.Color(255, 255, 255));
        imagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imagePanel.setMaximumSize(new java.awt.Dimension(640, 480));
        imagePanel.setMinimumSize(new java.awt.Dimension(640, 480));
        imagePanel.setPreferredSize(new java.awt.Dimension(640, 480));
        imagePanel.setRequestFocusEnabled(false);

        javax.swing.GroupLayout imagePanelLayout = new javax.swing.GroupLayout(imagePanel);
        imagePanel.setLayout(imagePanelLayout);
        imagePanelLayout.setHorizontalGroup(
            imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 638, Short.MAX_VALUE)
        );
        imagePanelLayout.setVerticalGroup(
            imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 478, Short.MAX_VALUE)
        );

        backgroundColorButton.setText("Set Background Color...");
        backgroundColorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backgroundColorButtonActionPerformed(evt);
            }
        });

        backgroundColorLabel.setText("<Background Color>");

        backgroundImageButton.setText("Set Background Image...");
        backgroundImageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backgroundImageButtonActionPerformed(evt);
            }
        });

        backgroundImageLabel.setText("<Background Image>");

        foregroundImageButton.setText("Set Foreground Image...");
        foregroundImageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                foregroundImageButtonActionPerformed(evt);
            }
        });

        foregroundImageLabel.setText("<Foreground Image>");

        coverGlowButton.setText("Set Cover Glow Image...");
        coverGlowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                coverGlowButtonActionPerformed(evt);
            }
        });

        coverGlowLabel.setText("<Cover Glow Image>");

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel4.setText("Image X:");

        jLabel5.setText("Image Y:");

        xSpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                xSpinStateChanged(evt);
            }
        });

        ySpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                ySpinStateChanged(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("Cover Image Location:");

        centerRadio.setText("Center");
        centerRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                centerRadioActionPerformed(evt);
            }
        });

        topRadio.setText("Top");
        topRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                topRadioActionPerformed(evt);
            }
        });

        bottomRadio.setText("Bottom");
        bottomRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bottomRadioActionPerformed(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel13.setText("Align:");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setText("Glow Image Location:");

        jLabel15.setText("Glow X:");

        jLabel16.setText("Glow Y:");

        glowSpinX.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                glowSpinXStateChanged(evt);
            }
        });

        glowSpinY.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                glowSpinYStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(ySpin)
                                    .addComponent(xSpin, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel7)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bottomRadio)
                            .addComponent(topRadio)
                            .addComponent(centerRadio)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel14))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16))
                        .addGap(54, 54, 54)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(glowSpinX, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                            .addComponent(glowSpinY, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(3, 3, 3)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(xSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(ySpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(glowSpinX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(glowSpinY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(centerRadio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(topRadio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bottomRadio)
                .addGap(53, 53, 53))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        minZoomSpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                minZoomSpinStateChanged(evt);
            }
        });

        jLabel2.setText("Min Zoom:");

        jLabel1.setText("Max Zoom:");

        falloffSpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                falloffSpinStateChanged(evt);
            }
        });

        jLabel3.setText("Zoom Falloff:");

        maxZoomSpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                maxZoomSpinStateChanged(evt);
            }
        });

        functionCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Linear" }));

        jLabel6.setText("Falloff Function:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setText("Falloff Parameters:");

        jLabel12.setText("Spacing:");

        spacingSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spacingSliderStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel12))
                        .addGap(47, 47, 47)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(functionCmb, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(falloffSpin)
                                    .addComponent(minZoomSpin)
                                    .addComponent(maxZoomSpin, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                                    .addComponent(spacingSlider))))))
                .addContainerGap(10, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(functionCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(maxZoomSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(minZoomSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(falloffSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(spacingSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setText("Preview Parameters:");

        jLabel10.setText("Cover Count:");

        coverCountSpin.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                coverCountSpinStateChanged(evt);
            }
        });

        jLabel11.setText("Selected Cover:");

        selectedSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                selectedSliderStateChanged(evt);
            }
        });

        jButton1.setText("Save Preview Image...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
                                .addComponent(coverCountSpin, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(22, 22, 22))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addContainerGap(92, Short.MAX_VALUE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addContainerGap(133, Short.MAX_VALUE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                            .addComponent(selectedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(40, 40, 40))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(coverCountSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(selectedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(27, 27, 27))
        );

        jMenu1.setText("File");

        saveMenuItem.setText("Save...");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(saveMenuItem);

        loadMenuItem.setText("Load...");
        loadMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(loadMenuItem);
        jMenu1.add(jSeparator1);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exitMenuItem);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(coverGlowButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(coverGlowLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(foregroundImageButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(foregroundImageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(backgroundColorButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(backgroundImageButton))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(12, 12, 12)
                                            .addComponent(backgroundColorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(backgroundImageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(backgroundColorButton)
                            .addComponent(backgroundColorLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(backgroundImageButton)
                            .addComponent(backgroundImageLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(foregroundImageButton)
                            .addComponent(foregroundImageLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(coverGlowButton)
                            .addComponent(coverGlowLabel))
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backgroundColorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backgroundColorButtonActionPerformed
        // TODO add your handling code here:
        Runnable showDialog = new Runnable() {
          public void run() {
            colorDialog.show();
          }
        };
        SwingUtilities.invokeLater(showDialog);
}//GEN-LAST:event_backgroundColorButtonActionPerformed

    private void coverGlowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_coverGlowButtonActionPerformed
        // TODO add your handling code here:
                // TODO add your handling code here:
        fc.showOpenDialog(this);
        File selFile = fc.getSelectedFile();

        if(selFile != null)
        {
            imagePanel.SetGlowImage(selFile);
            this.coverGlowLabel.setText(selFile.getName());
        }
}//GEN-LAST:event_coverGlowButtonActionPerformed

    private void backgroundImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backgroundImageButtonActionPerformed
        // TODO add your handling code here:
        fc.showOpenDialog(this);
        File selFile = fc.getSelectedFile();

        if(selFile != null)
        {
            imagePanel.SetBackgroundImage(selFile);
            this.backgroundImageLabel.setText(selFile.getName());
        }
}//GEN-LAST:event_backgroundImageButtonActionPerformed

    private void foregroundImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_foregroundImageButtonActionPerformed
        // TODO add your handling code here:
        fc.showOpenDialog(this);
        File selFile = fc.getSelectedFile();

        if(selFile != null)
        {
            imagePanel.SetForegroundImage(selFile);// selFile.getName());
            this.foregroundImageLabel.setText(selFile.getName());
        }
    }//GEN-LAST:event_foregroundImageButtonActionPerformed

    private void xSpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_xSpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetX(Integer.valueOf(xSpin.getValue().toString()));
    }//GEN-LAST:event_xSpinStateChanged

    private void ySpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ySpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetY(Integer.valueOf(ySpin.getValue().toString()));
    }//GEN-LAST:event_ySpinStateChanged

    private void maxZoomSpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxZoomSpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetMaxZoom(Integer.valueOf(maxZoomSpin.getValue().toString()));
    }//GEN-LAST:event_maxZoomSpinStateChanged

    private void minZoomSpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minZoomSpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetMinZoom(Integer.valueOf(minZoomSpin.getValue().toString()));
    }//GEN-LAST:event_minZoomSpinStateChanged

    private void falloffSpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_falloffSpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetFalloff(Integer.valueOf(falloffSpin.getValue().toString()));
    }//GEN-LAST:event_falloffSpinStateChanged

    private void coverCountSpinStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_coverCountSpinStateChanged
        // TODO add your handling code here:
        imagePanel.SetCoverCount(Integer.valueOf(coverCountSpin.getValue().toString()));
}//GEN-LAST:event_coverCountSpinStateChanged

    private void selectedSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_selectedSliderStateChanged
        // TODO add your handling code here:
        imagePanel.SetSelectedIndex(selectedSlider.getValue());
    }//GEN-LAST:event_selectedSliderStateChanged

    private void spacingSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spacingSliderStateChanged
        // TODO add your handling code here
        imagePanel.SetSpacing(Integer.valueOf(spacingSlider.getValue().toString()));
    }//GEN-LAST:event_spacingSliderStateChanged

    private void centerRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centerRadioActionPerformed
        // TODO add your handling code here:
        topRadio.setSelected(false);
        bottomRadio.setSelected(false);

        imagePanel.SetAlign(0);
}//GEN-LAST:event_centerRadioActionPerformed

    private void topRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topRadioActionPerformed
        // TODO add your handling code here:
        bottomRadio.setSelected(false);
        centerRadio.setSelected(false);

        imagePanel.SetAlign(1);
}//GEN-LAST:event_topRadioActionPerformed

    private void bottomRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bottomRadioActionPerformed
        // TODO add your handling code here:
        topRadio.setSelected(false);
        centerRadio.setSelected(false);

        imagePanel.SetAlign(2);
}//GEN-LAST:event_bottomRadioActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        //Get Filename
        String fname;
        // TODO add your handling code here:
        fc.setDialogTitle("Save as *.GIF");
        if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
        {

            File selFile = fc.getSelectedFile();

            if(selFile != null)
            {
                imagePanel.ScreenShot(selFile);
            }
        }
        
        fc.setDialogTitle("");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void glowSpinXStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_glowSpinXStateChanged
        // TODO add your handling code here:
        imagePanel.SetGlowX(Integer.valueOf(glowSpinX.getValue().toString()));
    }//GEN-LAST:event_glowSpinXStateChanged

    private void glowSpinYStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_glowSpinYStateChanged
        // TODO add your handling code here:
        imagePanel.SetGlowY(Integer.valueOf(glowSpinY.getValue().toString()));
    }//GEN-LAST:event_glowSpinYStateChanged

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        // TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        // TODO add your handling code here:
        String fname;
        // TODO add your handling code here:
        fc.setDialogTitle("Save as skin.xml");
        if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
        {
            File selFile = fc.getSelectedFile();

            if(selFile != null)
            {
                imagePanel.Save(selFile);
            }
        }
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void loadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMenuItemActionPerformed
        // TODO add your handling code here:
                // TODO add your handling code here:
        String fname;
        // TODO add your handling code here:
        fc.setDialogTitle("Select Skin XML file to load");
        if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
        {
            File selFile = fc.getSelectedFile();

            if(selFile != null)
            {
                imagePanel.Load(selFile);
            }
        }
    }//GEN-LAST:event_loadMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backgroundColorButton;
    private javax.swing.JLabel backgroundColorLabel;
    private javax.swing.JButton backgroundImageButton;
    private javax.swing.JLabel backgroundImageLabel;
    private javax.swing.JRadioButton bottomRadio;
    private javax.swing.JRadioButton centerRadio;
    private javax.swing.JSpinner coverCountSpin;
    private javax.swing.JButton coverGlowButton;
    private javax.swing.JLabel coverGlowLabel;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JSpinner falloffSpin;
    private javax.swing.JButton foregroundImageButton;
    private javax.swing.JLabel foregroundImageLabel;
    private javax.swing.JComboBox functionCmb;
    private javax.swing.JSpinner glowSpinX;
    private javax.swing.JSpinner glowSpinY;
    /*
    private javax.swing.JPanel imagePanel;
    */
    private Viewer imagePanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenuItem loadMenuItem;
    private javax.swing.JSpinner maxZoomSpin;
    private javax.swing.JSpinner minZoomSpin;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JSlider selectedSlider;
    private javax.swing.JSpinner spacingSlider;
    private javax.swing.JRadioButton topRadio;
    private javax.swing.JSpinner xSpin;
    private javax.swing.JSpinner ySpin;
    // End of variables declaration//GEN-END:variables

}
